#!/bin/bash
SQLITE_VERSION="sqlite-autoconf-3490100"
DOWNLOAD_FILE="${SQLITE_VERSION}.tar.gz"
DOWNLOAD_URL="https://sqlite.org/2025/${DOWNLOAD_FILE}"
WORK_DIR=$(pwd)
INSTALL_DIR=${WORK_DIR}/sqlite


mkdir -p "${INSTALL_DIR}"

echo "下载SQLite源码..."
wget -O "${DOWNLOAD_FILE}"  "${DOWNLOAD_URL}"

# 检查下载是否成功
if [ $? -eq 0 ]; then
	echo "SQLite 下载成功，文件名为 $SQLITE_VERSION.tar.gz"
else
	echo "SQLite 下载失败，请检查网络连接或下载链接。"
	exit 1
fi	

# 解压缩下载的文件
echo "解压文件中..."
tar xzf "$DOWNLOAD_FILE" || exit 1

cd "${SQLITE_VERSION}" || exit 1
echo "已成功进入 $SQLITE_VERSION 目录"

echo "配置编译选项..."
./configure --prefix="$INSTALL_DIR" --enable-shared

echo "开始编译..."
make || exit 1

echo "安装到指定目录..."
make install || exit 1

if [ -f "${INSTALL_DIR}/lib/libsqlite3.so" ]; then
	echo "编译成功！.so文件已生成"

fi

echo "清理临时文件..."
cd "${WORK_DIR}" || exit
rm -rf "${DOWNLOAD_FILE}" "${SQLITE_VERSION}"


